<?php
ini_set('memory_limit','500M');

$Folder	= "../uploaded_images/";

	
include('../classes/class.upload.php');
if(isset($_POST['Submit']))
{

	$Upload = $_FILES['main_prodimg_th'];
	
	$handle = new Upload($Upload);
	//var_dump($handle);
	if ($handle->uploaded)
	{
		$MyFileNameArr=explode('.',$Upload['name']);
		$MyFileNameArr=explode('-',$MyFileNameArr[0]);
		$MyFileName=$MyFileNameArr[0];
		$MyFileName=$MyFileName;
		
		$handle->image_convert = 'jpg';
		$handle->file_overwrite   = true;
		$handle->file_auto_rename = false;
		$handle->file_new_name_body = $MyFileName;

		$handle->image_resize     = false;
		$handle->allowed = array( 
								"image/gif",
                                "image/jpeg",
                                "image/pjpeg",
                                "image/png"
		);
		$handle->file_max_size = '2097152';
		$handle->Process($Folder);

		if ($handle->processed) {
	       $handle->clean();
	       $FileName=$handle->file_dst_name;
	       $FileType=$handle->file_src_mime;
	      
		   $DestinationPath=$handle->file_dst_path;
	     	$MyObject = new upload($DestinationPath.'/'.$FileName);
			   	$MyObject->file_overwrite	   	= true;
	       	   	$MyObject->image_resize        	= false;
	       	   	$MyObject->file_auto_rename    	= false;
	       	  	$MyObject->image_ratio	  		= true;
	       	   	$MyObject->process('uploaded_images/');
	   }
	}
}

?>

<script language="javascript">
function upload(){
	// hide old iframe
	var par = window.parent.document;
	var num = par.getElementsByTagName('iframe').length - 1;
	var iframe = par.getElementsByTagName('iframe')[num];
	iframe.className = 'hidden';
	document.iform.submit();
}

var par = window.parent.document;
var palceHolder = par.getElementById('myImage');
var removeButton = par.getElementById('RemoveImage');
var image_str = '<?=$img_str;?>';
var FolderName= '<?=$Folder; ?>';
var FileType= '<?=$FileType; ?>';

if(FileType=='FL')
{
	image_str='noimage.jpg';
}
</script>
<style>
body,td{
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9px;
	font-weight: normal;
	color: #333333;
	margin:0px;
}
</style>
<link href="css/common.css" rel="stylesheet" type="text/css" />
<form name="iform" action="" method="post" enctype="multipart/form-data">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="grid">
      <tr>
        <td align="center" valign="top">
			<table width="590" cellpadding="5" cellspacing="0">
			<?php
			if ($handle->error)
			{
			?>
			<tr>
			      <td width="10%" align="right" class="main_text"></td>
			      <td align="left"><?=$handle->error?></td>
			    </tr>
			<?php
			}
			?>
			   <tr>
			      <td width="25%" align="right" class="main_text"><b>Add Banner</b><span class="red">*</span></td>
			      <td align="left"><input name="main_prodimg_th" type="file" class="form" id="main_prodimg_th" size="30" /></td>
			    </tr>
			    <tr>
			      <td align="right" class="main_text"></td>
			      <td align="left"><input name="Submit" type="submit" class="prodmore_button" value="Upload Image" onclick="upload()" <? if(count($sess_imag_arr) >= MAXPRODUCTIMAGE) {?>disabled<? }?>/>
			          </span></td>
			    </tr>
			</table>
		</td>
	</tr>
</table>
</form>
